﻿using System;
using System.Collections.Generic;
using System.Text;

using System.IO;
using System.Net.Sockets;
using System.Net;

namespace Uniriotec.DC
{
    public class BufferedWriter<T> : StreamWriter where T : Stream
    {
        private T unbufferedStream;
        private Socket socket;

        public T UnbufferedStream
        {
            get { return unbufferedStream; }
            set { unbufferedStream = value; }
        }

        public BufferedWriter(T stream)
            : base(stream)
        {
            unbufferedStream = stream;
        }

        public BufferedWriter(Socket socket)
            : base(new NetworkStream(socket))
        {
            this.socket = socket;
        }

        public override void Write(string value)
        {
            /*
            IPAddress clientIPAddr   = ((IPEndPoint)socket.RemoteEndPoint).Address;
            int remotePort = ((IPEndPoint)socket.RemoteEndPoint).Port;

            IPAddress serverIPAddr   = ((IPEndPoint)socket.LocalEndPoint).Address;
            int localPort  = ((IPEndPoint)socket.LocalEndPoint).Port;
            
            
            Console.WriteLine("====BeginMessage=");
//            Console.WriteLine("====FROM=======");
//            Console.WriteLine("IP: " + serverIPAddr.ToString() + ":" + localPort);

//            Console.WriteLine("====TO=======");
//            Console.WriteLine("IP: " + clientIPAddr.ToString() + ":" + remotePort);

//            Console.WriteLine("=====Message====");
            Console.WriteLine("Sent: " + value);
            Console.WriteLine("====EndOfMessage=");
            */


            base.Write(value);
        }


    }
}